aspose file tools*
The moose likes Struts and the fly likes html - el tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html - el tags" Watch "html - el tags" New topic
Author

html - el tags

jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
hi guys

trying to come up with something, but stuck. making use of <html-EL . tags

here is the code

<html>

<c:set var="makeurl" value="/casemngt/OrderInfo1.do"/>

<html-el:form action="${makeurl}" method="post">
...
...other fields

...

<html-el:submit styleClass="BUTTON1" property="method" value="Save"> //save button
<c:set var="makeurl" value="/casemngt/OrderInfo1.do?method=save"/> //overriding makeurl
<c out value="{makeurl}"/>
</html-el:submit>

<html-el:submit styleClass="BUTTON1" property="method" value="FileCopy"> //Filecopy button
<c:set var="makeurl" value="/casemngt/OrderInfoCopyFiles.do?method=copyFiles"/>//overriding makeurl
<c out value="{makeurl}"/>
</html-el:submit>
</html-el:form>
</html>

in above code:
when save button is clicked i want to override value of makeurl from
/casemngt/OrderInfo1.do to /casemngt/OrderInfo1.do?method=save

similarly Filecopy button when clicked should override makeurl to /casemngt/OrderInfoCopyFiles.do?method=copyFiles..

any ideas?
thanks
J
[ March 02, 2007: Message edited by: jay roy ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The problem here is that you're trying to do something on the server-side that can only be done on the client-side. Once the expression

has been evaluated and rendered into HTML, it's then sent back to the browser. At that point, there's absolutely nothing you can do in server-side code (i.e. JSP code) to change it. It's set in stone.

If you want to change it based on the click of a button, you must use a client-side technology such as JavaScript. Example:

Note: onklick above should be onclick. It was changed to get around the JavaRanch filters.


Merrill
Consultant, Sima Solutions
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
is there any way i can avoid javascript and make use of all the tags i have
thanks for response
J
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There is absolutely no possibility of doing it the way you have shown us above.

There may be other ways to do it than the one I demonstrated above, but the only ones I can think of still involve the use of JavaScript.

The bottom line here is that the only way you can change an action URI once it has been rendered to the browser is by using a technology that runs on the browser. Anything you can do in a JSP runs on the server, not the browser, and hence can not possibly work.

Is there a reason you're trying to avoid JavaScript? IMHO, you can't really build the type of interactive User Interface that users expect these days without using at least some JavaScript.
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
my goal is to avoid javascript completely, thats the reason why i was trying to make use of html-el tags to come up with something.
if you can provide some ideas ,i 'll greatly appreciate

thanks
J
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Frist of all let me make my position clear: I do not agree that it's a good thing to try and avoid JavaScript, and I see no good reason for doing so.

However, if you really want to avoid JavaScript, one solution would be to abandon the idea of trying to change the action URI when each button is pressed, and have them all go to the same Action URI. You can then use either a DispatchAction or LookupDispatchAction to route the requests appropriately once the form has been submitted. See the Struts JavaDoc for more details.

Another possibility: Does this really need to be a form? You might be able to use hyperlinks instead of submit buttons.
[ March 02, 2007: Message edited by: Merrill Higginson ]
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
ok this is why i am avoiding javascript:
i have two buttons (one of the type html:submit and other of the type html:button) something like this




<html-el:form action="/casemngt/OrderInfoCopyFiles.do?method=copyFiles" method="post">
Address CITY:<html:text property="city" style="20" />

<html:submit property="method" value="Copy Files">copyfiles</html:submit> //this tag calls <html-el:form action="${makeurl}"..>

<html:button onKlick="document.forms[0].action='../casemngt/OrderInfo1.do?method=save';document.forms[0].submit()" property="method" value="Save"/> //this is javaascript

</html-el:form>


when i enter something in <html:text property="city" style="20" /> and hit 'copyfiles' , the value comes up in my action class BUT
when i enter something in <html:text property="city" style="20" /> and hit 'save' ,the value does NOT comes up in my action class

this is my code in action class

public ActionForward save(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionErrors errors = new ActionErrors();
DynaActionForm dynaForm = (DynaActionForm)form;
try {
System.out.println("Value of city1:" +(String)dynaForm.get("city"));

}
catch (Exception e) {

}
public ActionForward copyFiles(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionErrors errors = new ActionErrors();
//DynaActionForm dynaForm = (DynaActionForm)form;
DynaActionForm dynaForm = (DynaActionForm)form;
try
{
System.out.println("Value of city1:" +(String)dynaForm.get("city"));

}


and i just dont know why it happens.

thanks for the help, i greatly appreciate it.
J

[ March 02, 2007: Message edited by: jay roy ]
[ March 02, 2007: Message edited by: jay roy ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The problem is that when you specify property="method" in your <html:button> tag, that is overriding the "?method=save" part of the URI. The solution is to put something else.. anything else as the property in your <html:button> tag. Example:

[ March 02, 2007: Message edited by: Merrill Higginson ]
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
ok i modified my code like this
<html-el:form action="/casemngt/OrderInfoCopyFiles.do?method=copyFiles" method="post">

Address CITY:<html:text property="city" style="20" />
<html:submit property="method" value="Copy Files"/> //is property="method" okay here
<html:button onklick="document.forms[0].action='../casemngt/OrderInfo1.do?method=save';document.forms[0].submit()" property="saveButton" value="Save"/>

so do i change in struts config too like this
<action path="/casemngt/OrderInfo1"
name="OrderInfoBean"
scope="request"
validate="false"
input="OrderInfo.display"
type="com.aoc.ffm.uifsa.actions.OrderInfoAction"
parameter="saveButton"> // do i change it here
<forward name="success" path="OrderInfo.display" >
</forward>
</action>

<action path="/casemngt/OrderInfoCopyFiles"
name="OrderInfoBean"
scope="request"
validate="false"
type="com.aoc.ffm.uifsa.actions.OrderInfoAction"
parameter="method"> //is property="method" okay here
<forward name="success" path="OrderInfo.display"/>
</action>

thanks very much
[ March 02, 2007: Message edited by: jay roy ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by jay roy:
so do i change in struts config too ?

No, you don't. Since you're passing the "method" parameter in the URI, "method" is the parameter you should use to control your DispatchAction. In this case, "saveButton" is a throw-away parameter that you aren't going to use at all.
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
wow, just followed what you said, i dont know why its not working
when i click on
<html:button onklick="document.forms[0].action='../casemngt/OrderInfo1.do?method=save';document.forms[0].submit()" property="saveButton" value="Save"/>
it doesnt pass the 'city' field value to action class. but <html:submit works fine.


<html-el:form action="/casemngt/OrderInfoCopyFiles.do?method=copyFiles" method="post">

Address CITY:<html:text property="city" style="20" />
<html:submit property="method" value="Copy Files"/>
<html:button onklick="document.forms[0].action='../casemngt/OrderInfo1.do?method=save';document.forms[0].submit()" property="saveButton" value="Save"/>

</html-el:form>

my struts config
<action path="/casemngt/OrderInfo1"
name="OrderInfoBean"
scope="request"
validate="false"
input="OrderInfo.display"
type="com.aoc.ffm.uifsa.actions.OrderInfoAction"
parameter="method">
<forward name="success" path="OrderInfo.display" >
</forward>
</action>

<action path="/casemngt/OrderInfoCopyFiles"
name="OrderInfoBean"
scope="request"
validate="false"
type="com.aoc.ffm.uifsa.actions.OrderInfoAction"
parameter="method">
<forward name="success" path="OrderInfo.display"/>
</action>

if you can kindly look into it,i'll greatly appreciate. i think i am missing a small thing somewhere..
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Let me make sure I understand what is happening. You say when you click the button, it does submit the form and call the correct method on your action class, but when it gets there, the city is null. Is this correct?

Have you tried retrieving it both as myform.getCity() and request.getParameter("city") ? Do they both return null?
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
>>when it gets there, the city is null. Is this correct?
yes, exactly

I am using DynavalidatorForm, so my form bean is something like
<form-beans>
<form-bean name="OrderInfoBean" type="org.apache.struts.validator.DynaValidatorForm" dynamic="true">
<form-property name="city" type="java.lang.String" />
<form-property name="state" type="java.lang.String" />
</form-bean>
</form-beans>

and because i am using DyanValidatorForm which extends DyanActionForm
in my action class i am doing


public ActionForward save(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionErrors errors = new ActionErrors();
DynaActionForm dynaForm = (DynaActionForm)form;

try {



System.out.println("Inside save method");

System.out.println("Value of city1:" +(String)dynaForm.get("city"));

}
its going inside the method since i see the message "Inside save method" (when save button is clicked), but i dont see the city value which i entered
its just blank.

and request.getParameter("city") returns null. i just tested.

now in other scenario when "Copy Files" is clicked this line in jsp
<html:submit property="method" value="Copy Files"/> //it goes to <html:form..

and gets routed to another method in action class shown below

public ActionForward copyFiles(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionErrors errors = new ActionErrors();
DynaActionForm dynaForm = (DynaActionForm)form;

try {



System.out.println("Inside copy method");

System.out.println("Value of city1:" +(String)dynaForm.get("city"));

}

and i am able to see the city value which i have entered in the jsp in the above method copyFiles

thanks
J
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
and in the jsp i have

<html:submit property="method" value="Copy Files"/>
the above line shows the city field value in action class

and the below line does not show the city field value in action class
<html:button onklick="document.forms[0].action='../casemngt/OrderInfo1.do?method=save';document.forms[0].submit()" property="saveButton" value="Save"/>

any ideas greatly appreciated
thanks
J
[ March 02, 2007: Message edited by: jay roy ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I don't know what to tell you at this point except just to keep looking. Just to show you I know this works, I created a quick test application that very closely follows the pattern of your problem. It runs and works as exepcted. You may want to plug it in and run it. By doing so, it may trigger some thought process that will help you see what is wrong in your application.

the struts-config.xml entries:

The Action classes:

The JSP: /testDispatch.jsp

Log file when running:
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
kool,let me plug in your code and try.
the only difference i see is in your form-beans section you have
this line
<form-property name="method" type="java.lang.String" initial="" reset="true"/>
and i dont . do you think thats causing the problem.

i couldnt thank you more.
greatly appreciate your help and patience.
thanks
Jay
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
thanks , i finally fixed it. there was no problem with the code , i had included an another jsp in this jsp using <jsp:include > and when i was doing onklick="document.forms[0].action=' .. , it was submitting both the jsp's and that was causing the problem , so instead of doing document.forms[0]..., i did document.form-bean-name.action=' .. and that fixed the problem.

thanks a lot for your help,
J
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
Any sugessions on my next practical scenario greatly appreciated
http://www.coderanch.com/t/55785/Struts/encode-decode-url-query-string
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: html - el tags