You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Srinivasarao Nandiwada <sr...@netscape.net> on 2002/03/07 17:13:04 UTC

specifying dynamic value for logic:equal

Hi,

Let me briefly explain the problem  - I am using a select box in edit 
page and wanted to use simple text corresponding to the selected value 
in view page. My select box consists of the following :

Label One   ---> value 1
Label Two   ---> value 2
Label Three ---> value 3

I am using html:select and html:options in edit page and it works great. 
  However, my form bean only stores the value of the property, and in 
the view page, I need to convert the value of the property back to 
label. How do I do this without using scriptlets? I thought of using 
logic:iterate and logic:equal tags, but logic:equal tag requires a 
constant value which does not work for me as my select box is generated 
from the values from database. I thought of creating another property 
corresponding to label in form bean, but is there any better solution to 
this?

Thanks,
nsr


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: specifying dynamic value for logic:equal

Posted by keithBacon <ke...@yahoo.com>.
Code posted below - hope it makes sense.
Keith.

--- Srinivasarao Nandiwada <sr...@netscape.net> wrote:
> Hi,
> 
> Let me briefly explain the problem  - I am using a select box in edit 
> page and wanted to use simple text corresponding to the selected value 
> in view page. My select box consists of the following :
> 
> Label One   ---> value 1
> Label Two   ---> value 2
> Label Three ---> value 3
> 
> I am using html:select and html:options in edit page and it works great. 
>   However, my form bean only stores the value of the property, and in 
> the view page, I need to convert the value of the property back to 
> label. How do I do this without using scriptlets? I thought of using 
> logic:iterate and logic:equal tags, but logic:equal tag requires a 
> constant value which does not work for me as my select box is generated 
> from the values from database. I thought of creating another property 
> corresponding to label in form bean, but is there any better solution to 
> this?
> 
============================================================
In form bean get/setLinkSelectionOption. These are the values
as stored on DB.
User sees the labels.
============================================================
In jsp.
<html:select name="linkListForm" property="linkSelectionOption" >
	<html:options  collection="linkSelectionOptions"
		property="option"
		labelProperty="label" />
</html:select>&nbsp;&nbsp;

===========================================================
The class referred to.

package com.biff.biffapp1.app;

import java.util.ArrayList;

import com.biff.utils.ZUtils;
          /**
          * The option object
          * plus static methods to return the array list of the real data.
          * dodgy having list underneath the single list item object -qq?
          */
public final class LinkSelectionOption  extends Object {
	private final static String THIS_NAME = "LinkSelectionOption";

	private String lsOption = null;
	private String lsLabel  = null;

	LinkSelectionOption(String  lsOption, String lsLabel) {
		this.lsOption = lsOption;
		this.lsLabel  = lsLabel;
	}

	public String getOption() {
		return lsOption;
	}
	public void setOption(String lsOption) { //never called!
		this.lsOption = lsOption;
	}
	public String getLabel() {
		return lsLabel;
	}
	// needed qq?
	public void setLabel(String lsLabel) {
		this.lsLabel = lsLabel;
	}

	static private void dbmi(String message) {
		ZUtils.writeLog(THIS_NAME, ZUtils.INFO_LEVEL,  message);
	}
	static private void dbmd(String message) {
		ZUtils.writeLog(THIS_NAME, ZUtils.DEBUG_LEVEL,  message);
	}
	static private void dbmw(String message) {
		ZUtils.writeLog(THIS_NAME, ZUtils.WARNING_LEVEL,  message);
	}

	static private ArrayList displayTypeOptions = null;
	static public ArrayList getLinkSelectionOptions() {
		if (displayTypeOptions == null) {
			displayTypeOptions = new ArrayList(12);
			displayTypeOptions.add(new LinkSelectionOption("allLinks", "All Links"));
			displayTypeOptions.add(new LinkSelectionOption("myLinks"  , "Only My
Links"));
		}
		return displayTypeOptions;
	}
	static public String getDefaultOption() {
		String sss =
((LinkSelectionOption)getLinkSelectionOptions().get(0)).getOption();
		dbmd("getDefaultOption: returning:"+ sss);
		return sss;
	}
} // end Class LinkSelectionOption


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search the archive:-
http://www.mail-archive.com/struts-user%40jakarta.apache.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Bacon - Looking for struts work - South-East UK.
phone UK 07960 011275

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>