J
james
I've been crash-course learning java, jsp, servlets, struts, etc
(Coming over from php & asp, and I love it!). I'm trying to figure out
proper style in the process.
I've been creating a custom taglib for my app to retrieve data so JSP
pages can render them. Do I have to create a separate class for each
custom tag? For servlets/struts, I can use a DispatchAction class to
feed multiple actions into the same class, using a parameter to tell
which method I want to invoke. Is there anything similar with custom
tags? I would like to have the following.
<myApp:getItems parameter="allItems"/>
<myApp:getItems parameter="oldItems"/>
And they would correspond to the following methods, respectively:
class GetItemsTag extends TagSupport {
public void getAllItems() { ... }
public void getOldItems() { ... }
}
I can do this with two separate tag classes, or by using a big "if (
parameter.equals(...) ) {" for each action, but this would seem to make
things just one bit simpler. Is there any such shortcut? Am I trying
to abuse the model / view paradigm?
Also, as far as I can see, in a typical struts app I have a couple of
possibilities for rendering pages:
1) I can goto page.jsp and use custom tags to grab all the data
necessary, then post any forms to an action...
2) or I can always go to page.do, have that action setup all the
necessary data in request vars, and then forward to the proper
rendering JSP page.
Are both of these styles acceptable? Is either blatantly wrong, or
does it come down to preference and pros/cons of each style? What are
your preferences?
Thanks for all feedback, I love java after dealing with ASP / PHP for
so long.
James
(Coming over from php & asp, and I love it!). I'm trying to figure out
proper style in the process.
I've been creating a custom taglib for my app to retrieve data so JSP
pages can render them. Do I have to create a separate class for each
custom tag? For servlets/struts, I can use a DispatchAction class to
feed multiple actions into the same class, using a parameter to tell
which method I want to invoke. Is there anything similar with custom
tags? I would like to have the following.
<myApp:getItems parameter="allItems"/>
<myApp:getItems parameter="oldItems"/>
And they would correspond to the following methods, respectively:
class GetItemsTag extends TagSupport {
public void getAllItems() { ... }
public void getOldItems() { ... }
}
I can do this with two separate tag classes, or by using a big "if (
parameter.equals(...) ) {" for each action, but this would seem to make
things just one bit simpler. Is there any such shortcut? Am I trying
to abuse the model / view paradigm?
Also, as far as I can see, in a typical struts app I have a couple of
possibilities for rendering pages:
1) I can goto page.jsp and use custom tags to grab all the data
necessary, then post any forms to an action...
2) or I can always go to page.do, have that action setup all the
necessary data in request vars, and then forward to the proper
rendering JSP page.
Are both of these styles acceptable? Is either blatantly wrong, or
does it come down to preference and pros/cons of each style? What are
your preferences?
Thanks for all feedback, I love java after dealing with ASP / PHP for
so long.
James