voyent
Need an example of using InputRichText  XML
Forum Index -> Components Go to Page: 1, 2 Next 
Author Message
chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


First of all, I must say that ICEfaces is a great product.

I’m using inputRichText component and I have some issues.

I need to update the value in inputRichText from the backing bean. But it’s not working.

I have two panel collapsible components. In the first one, there is a selectOneMenu component. The inputRichText is in the second panel, which not rendered at first. The second panel is rendered when a value is selected from the selectOneMenu.

There is a value change listener for the selectOneMenu component and the listener method will set a new value for the value bound by the inputRichText. I also bound the inputRichText with the corresponding component class and set the submitted value. That’s also not working.

What could be the issue I'm facing here?

I'm using ICEfaces 1.7.0. and Java 1.6.0_02

I created a sample project in Eclipse and I have attached.

I read that inputRichText just wraps the FCKeditor in another forum thread. Does this mean that we have to use Javascript API? Please let me know how to use the inputRichText component.

I’m new to ICEfaces and FCKeditor.

Thanks in advance.

Chrishantha
 Filename ICEfacesTest.zip [Disk] Download
 Description Sample project created from Eclipse. There are two directories, "src" and "WebContent"
 Filesize 5 Kbytes
 Downloaded:  521 time(s)


Isuru Perera
projo

Joined: 03/Oct/2007 00:00:00
Messages: 83
Offline


try to put the update logic in the getter methode... thereabout :
Code:
		public String getMessage() {
 		message = o.getMessage();
 		return message;
 	}
chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


Hi projo,

Thanks for you reply.

I tried that.. But still it's not working..

I think the problem is with the FCKeditor. The editor just keeps the initial value.

There is another forum thread http://www.icefaces.org/JForum/posts/list/6057.page, which says that InputRichText just wraps the FCKeditor.

I need to know how to set a new value to inputRichText.

Isuru Perera
sudha

Joined: 27/Dec/2007 00:00:00
Messages: 7
Offline


When the richText loads for the first time it puts a value into the request map (param name: richTextClientIdvalueHolder)& then keeps reusing it. Hence the value from the bean is not being picked up.

You need to remove this value from the request map & that will force the component to pick up the value from the backing bean.
chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


Hi sudha,

I did what you said and still it's not working...

Code:
 FacesContext context = FacesContext.getCurrentInstance();
 String clientID = messageInputRichText.getClientId(context);					
 Map<String, String> requestParameterMap = context.getExternalContext().getRequestParameterMap();
 


I found that there are two parameters with following names.

1. <InputRichText_clientId> (eg. iceForm:rtxtMessage)
2. <InputRichText_clientId> + "valueHolder" (eg. iceForm:rtxtMessagevalueHolder)

Both parameters contain the initial value of the inputRichText.

First I tried removing and then tried to replace the values in map.. But didn't work..

In the final page source (html), I see that the initial value is in a hidden field.

Code:
 <input id="iceForm:rtxtMessagevalueHolder" name="iceForm:rtxtMessagevalueHolder" type="hidden" value="<p><b><i>Message:</i> 1</b></p>" />
 


Does anyone have an idea about setting a new value to InputRichText?

Isuru Perera
chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


Hi all,

I found a workaround for my issue. After 3 days of hard work I decided to update DOM manually using Javascript.

I also don't know whether this has any side effects, but this works fine for me.

Following is the javascript call inside my value change listener method

Code:
 StringBuilder script = new StringBuilder();
 script.append("var valueHolder = document.getElementById('").append(clientID).append("valueHolder").append("');");
 script.append("if (valueHolder && valueHolder.value) {");
 script.append("valueHolder.value = '").append(message).append("';");
 script.append("};");
 
 JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), script.toString());
 



If anyone found a better solution, please let me know..

Isuru Perera
chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


Hi all,

It seems that my workaround is not successful. There is a problem when the message contain some special characters. For example, single quote and new line character.

I replaced all of them.. but still I don't think that's a good solution..

Code:
 	String javascriptSafeMessage = message.replaceAll("\\\\", "\\\\\\\\");
 	javascriptSafeMessage = javascriptSafeMessage.replaceAll("\t", "\\\\t");
 	javascriptSafeMessage = javascriptSafeMessage.replaceAll("\n", "\\\\n");
 	javascriptSafeMessage = javascriptSafeMessage.replaceAll("\r", "\\\\r");
 	javascriptSafeMessage = javascriptSafeMessage.replaceAll("\f", "\\\\f");
 	javascriptSafeMessage = javascriptSafeMessage.replaceAll("\b", "\\\\b");
 	javascriptSafeMessage = javascriptSafeMessage.replaceAll("\"", "\\\\\"");
 	javascriptSafeMessage = javascriptSafeMessage.replaceAll("'", "\\\\'");
 
 	StringBuilder script = new StringBuilder();
 	script.append("var valueHolder = document.getElementById('").append(clientID).append("valueHolder").append("');");
 	script.append("if (valueHolder && valueHolder.value) {");
 	script.append("valueHolder.value = '").append(javascriptSafeMessage).append("';");
 	script.append("};");
 


The FCKeditor uses a hidden field from the page. I think that hidden field is generated only once. ICEfaces doesn't update that value.
Client ID: iceForm:rtxtMessage

Code:
 <input id="iceForm:rtxtMessagevalueHolder" name="iceForm:rtxtMessagevalueHolder" type="hidden" value="Message" />
 


In each page update, following javascript sets the hidden field value to inputRichText.

Code:
 Ice.FCKeditorUtility.updateValue ('iceForm:rtxtMessage');
 


Can anyone please give me a solution?

Isuru Perera
sudha

Joined: 27/Dec/2007 00:00:00
Messages: 7
Offline


Hi chrishantha,

I think it might be best to go to the requestMap solution i posted a few days back.

You need to bind the richText component & in the setter method do the following

Map map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
map.remove(richTextClientId+"valueHolder");

This will force the richText component to use the value from the bean.



chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


Hi sudha,

I tried what you said. It didn't work. That's why I tried to change the value from Javascript.

Can you please give me a sample code? I see that there is a request parameter with the name you mentioned. But removing it has no effect.

What do you mean by
You need to bind the richText component & in the setter method do the following  


Following is my value change listener.

Code:
 public void typeValueChangeListener(ValueChangeEvent event) {
 	System.out.println("TestBackingBean.typeValueChangeListener()");
 	int id = (Integer) event.getNewValue();
 	if (id > 0) {
 		for (TestObject o : testObjectList) {
 			if (o.getId() == id) {
 				selectedTestObject = o;
 				message = o.getMessage();
 				FacesContext context = FacesContext.getCurrentInstance();
 				String clientID = messageInputRichText.getClientId(context);
 				System.out.println("clientID: " + clientID);
 				Map<String, String> requestParameterMap = context.getExternalContext().getRequestParameterMap();
 				System.out.println("requestParameterKeys: " +  requestParameterMap.keySet());
 				String valueHolder = clientID + "valueHolder";
 				System.out.println(clientID + ": " + requestParameterMap.get(clientID));
 				System.out.println(valueHolder + ": " + requestParameterMap.get(valueHolder));
 				requestParameterMap.remove(valueHolder);
 				System.out.println("requestParameterKeys: " +  requestParameterMap.keySet());
 				System.out.println("message: " + message);
 				messageInputRichText.setSubmittedValue(message);
 				
 				selected = true;
 				break;
 			}
 		}
 	} else {
 		message = null;
 		selected = false;
 	}
 	System.out.println("Leaving TestBackingBean.typeValueChangeListener()");
 }
 


Output:


May 5, 2008 9:27:18 PM org.apache.tomcat.util.http.Parameters processParameters
WARNING: Parameters: Invalid chunk ignored.
TestBackingBean.typeValueChangeListener()
clientID: iceForm:rtxtMessage
requestParameterKeys: [iceForm:rtxtMessagevalueHolder, ice.event.type, ice.event.target, ice.view, iceForm:j_id14, ice.focus, ice.event.captured, focus_hidden_field, icefacesCssUpdates, ice.submit.partial, iceForm:j_id16Expanded, iceForm:rtxtMessageDisabled, iceForm:rtxtMessage, rand, ice.session, iceForm, javax.faces.ViewState]
iceForm:rtxtMessage: <p><b><i>Message:</i> "10"</b></p>
iceForm:rtxtMessagevalueHolder: <p><b><i>Message:</i> "10"</b></p>
requestParameterKeys: [ice.event.type, ice.event.target, ice.view, iceForm:j_id14, ice.focus, ice.event.captured, focus_hidden_field, icefacesCssUpdates, ice.submit.partial, iceForm:j_id16Expanded, iceForm:rtxtMessageDisabled, iceForm:rtxtMessage, rand, ice.session, iceForm, javax.faces.ViewState]
message: <p><b><i>Message:</i> "5"</b></p>
Leaving TestBackingBean.typeValueChangeListener()


I can see that the parameter map doesn't contain the "clientID + "valueHolder"" after removing.

But the inputRichText still get the old value. There's no change in the hidden field in the generated page.

Code:
 <input id="iceForm:rtxtMessagevalueHolder" name="iceForm:rtxtMessagevalueHolder" type="hidden" value="<p><b><i>Message:</i> "10"</b></p>" />
 

Isuru Perera
sudha

Joined: 27/Dec/2007 00:00:00
Messages: 7
Offline


Hi chrishantha,

Bind the component as follows

<ice:inputRichText toolbar="Basic" height="325px" binding="#{editResumeBean.inputRichText}" value="#{editResumeBean.richTextValue}" ></ice:inputRichText>

The backing bean needs to have

private InputRichText inputRichText;
public InputRichText getInputRichText() {
return inputRichText;
}

public void setInputRichText(InputRichText inputRichText) {
this.inputRichText = inputRichText;
if(this.inputRichText != null){
if(richTextClientId != null){
Map map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
map.remove(richTextClientId+"valueHolder");
}
}
}

chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


Hi sudha,

Wow!! It worked..


Thank you very much...

Isuru Perera
Eabin

Joined: 18/Nov/2006 00:00:00
Messages: 20
Offline


Thank you, this is a nice workaround.

But i really think the behaviour of inputRichText is very counter-intuitive and should be fixed in the next release.
style_x7

Joined: 26/May/2008 00:00:00
Messages: 4
Offline


Thank you sudha and chrishantha for posting this problem :)

I was evaluating the rich text component and was about to drop it off. Found the solution off here and hopefully this component wont give me any more problems..

It is pretty a crucial issue (at least to me) that there are people who create a report using the rich text component and allow others to open and edit it. Without the workaround, the editor will just stubbornly hold on to the 1st report opened and refuse to load the other reports.

Hope the developers can resolve this soon. Thanks.
chrishantha

Joined: 04/Mar/2008 00:00:00
Messages: 153
Offline


Hi all,

Unfortunately, the workaround is not perfect. The InputRichText shows the initial value again when I click on another component with partialSubmit="true".

I posted a new topic and please follow it for more details.

http://www.icefaces.org/JForum/posts/list/9012.page



Isuru Perera
bbxfnet

Joined: 15/Apr/2010 00:00:00
Messages: 5
Offline


See http://www.icefaces.org/JForum/posts/list/19551.page
 
Forum Index -> Components Go to Page: 1, 2 Next 
Go to:   
Powered by JForum 2.1.7ice © JForum Team