aspose file tools*
The moose likes Struts and the fly likes c:set equivalent in struts tag ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "c:set equivalent in struts tag ?" Watch "c:set equivalent in struts tag ?" New topic
Author

c:set equivalent in struts tag ?

M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
Hi,


I am looking out for a <c:set> equivalent tag in struts tag library. If it is possible using struts tag, i would appreciate if an example of the usage is also provided.

The purpose is to overwrite a value of one of the attributes of the form bean. This could have been acheived using c:set, but since we are not using any standard tags, would like to achieve the same using struts tag. So was looking out for a alternative of c:set in struts ...


TIA
[ May 03, 2007: Message edited by: Manish Sachdev ]

Regards, Manish
SCJP 1.4
Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
How about:

-Jim
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
Thanks Jim,

In my case, this solution won't work. I am checking the validationErrors property of form bean, and if that form is processed with error's, i need to overwrite one of the property of the form bean before processing the rest of the jsp.

I am not sure whether <bean : define> tag will be useful to me, i am currently evaluating this tag to see if it helps me to overwrite one of the form bean's property at runtime.


TIA
[ May 03, 2007: Message edited by: Manish Sachdev ]
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
Kindly help, still haven't got any solution on this
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
As far as I know, there is no way to do it with Struts tags. Since <c:set> will do it, I don't see any good reason not to use it. Personally, I prefer to use the more standard JSTL tags to the Struts tags whenever there is a choice between the two.


Merrill
Consultant, Sima Solutions
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
Hi Merrill,

I totally agree with you, even my preference has always been JSTL tags. The reason for not using it is because, struts tags are used all over the project and not a single jsp page contains JSTL tags. Just an effort to make it consistent with the current code, so that it does not create any maintainence problems in the future, i thought of sticking to struts tags.


TIA
Jim Hardin
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
Manish,
Not that you need to explain it to me -- this is your question after all, but I don't quite understand why:

won't help you with your goal of:

The purpose is to overwrite a value of one of the attributes of the form bean

-Jim
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
Jim,

I already have one hidden variable with name "dispatch" in the JSP page.

The entire JSP page works on the basis of some condition. For example, if the value of "dispatch" is "view", we get a non editable page, and if the value of dispatch is "edit" it will show the page in edit mode etc.

Now when we submit the page, the dispatch value being passed is "save". The validations are being done in the validate method of the form. So if the validation fails, it returns the control back to the JSP. But this time the value which was last submitted for dispatch was "Save".

My goal is to interpret, at the TOP of the JSP page, whether there are any validation errors or not, which i have already done. And if there are errors, then i need to change the value of "dispatch" from "Save" to "Edit" at the TOP in the JSP file, so that rest of the code is executed as per "Edit" condition and the page gets displayed in the "Edit" mode.

This varaiable named "dispatch" is a ActionForm variable as well as it is present in the request scope. I found that, one which the JSP page interprets is a request scope variable. I think, we can no way change values of variables present in request scope at runtime, while the request is being interpreted.

I also tried accessing ActionForm variable in the JSP by refferring it as myForm.dispatch, but even that does not work . Here is one small code snippet....




I hope I answered your question. Trying to get rid of this problem, any help will be appreciated


TIA
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
Ideally, you probably shouldn't use the dispatch form variable to control what html is displayed. Create some other hidden form variable that will not be changed upon submittal.

If you want to experiment try this: In your xml file, you might be able to append ?dispatch=edit to the input forward. I think it might overwrite the set form variable if validation fails.
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
Thanks Dom,

That would have been a good idea, I would have tried that, but we are using tiles and have given tiles id for the input property in struts-config.xml


<action path="/changePriceAdj" type="com.sunmed.om.controller.ChangePriceAdjustmentAction" name="changePrice" scope="session" validate="true" input="tile.change_price_adjustment">
<forward name="refreshLineDetail" path="/addLineItemFromDetail.do?dispatch=editLineItem" />
<forward name="success" path="tile.order_entry_line_detail" />
<forward name="cancel" path="tile.order_entry_line_detail" />
<forward name="edit" path="tile.change_price_adjustment" />



below is the tiles snippet




TIA
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
Thanks all,

I worked out a solution using logic tags as shown below:



<logic:equal name="changePrice" property="dispatch" value="edit">
.................................................
.........here goes the code to be executed.......
.................................................
</logic:equal>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c:set equivalent in struts tag ?