Xpages partial refresh radio button - radio-button

I have a radio button group with 2 values: Protected and Public.
I want to add the option that if protected selected: a field(laben:hidden) to be invisible, and if is public to be visible.
I have this code at the field visible property:
var protectie = getComponent("protect").getValue();
if(protect == "Public")
{ return true; }
if(protect == "Protected")
{ return false; }
and I have a partial refresh on the radio button goup, on onChange method.
It is working fine, but if I switch 2 times from protected to public I get the following error:
No element to submit with id view:_id1:_id2:_id31:hidden.
Thank you,
Florin

The error occurs because you want to refresh id "hidden" but it is not rendered at this time.
Frame your field/label with a panel. Partial refresh this panel ("panel1") but let the visible property in field/label.
<xp:panel id="panel1">
... your field/label ...
</xp:panel>

Related

How to add clickhandler to the subrow of the celltablebuilder

I am able to build custom rows with celltablebuilder. When clicking on a particular anchor cell, I am able to build additional subrows for that row. This subrow has buttons, when clicking on the button I have do some action. I am able to add buttons with clickhandler in the subrow, but when clicking on the button nothing is happening clickhandler is not firing.
Can anybody please help.
protected void buildRowImpl(GridDTO rowValue, int absRowIndex ) {
buildRows(rowValue, absRowIndex, true);
if (showingFriends.contains(rowValue.getComponentId())) {
buildAdditonalRows( absRowIndex, gridDTO);
}
}
private void buildAdditonalRows(int index, GridDTO rowValue, ){
TableRowBuilder row = startRow();
td = row.startTD();
if(rowValue.getXpath() != null){
//td.text(rowValue.getXpath());
renderCell(td, createContext(1), cellTable.getColumn(1), rowValue);
}else{
td.text("");
}
td.endTD();
td = row.startTD();
Button button = new Button ();
button.setText("Save");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("ssss");
}
});
DivBuilder div = td.startDiv();
div.html(new afeHtmlBuilder().appendHtmlConstant(button.toString()).toSafeHtml());
div.end();
td.endTD();
row.endTR();
}
CellPreviewEvent provides subindex. You can use it to get subrow value.
Example usage :
dataGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<TreeItem>() {
#Override
public void onCellPreview(final CellPreviewEvent<TreeItem> event) {
if(event.getNativeEvent().getType().equals(BrowserEvents.CLICK)){
if(event.getContext().getSubIndex()>0){
event.getValue().getChild(event.getContext().getSubIndex()-1);
}
}
}
});
Or you can provide custom CellPreviewEvent.Handler implementation with selectionMode. For more details you can look at AbstractHasData
I had a similar situation where i needed a widget inside a cell to listen for click events... What i found out is that the widget doesn't respond to events once you inserted it into a cell (In other words, only the actual HTML that makes up for the widget gets put into the cell, any kind of event handling isn't included). The work around is to add the events to the Cell (You can make a custom cell class for that particular cell-widget and override OnBrowserEvent to listen for events.)
See GWT: On adding custom widget to celltable losing events of the custom widgets for a more eloquent explanation and example code.

How to set customized tabstop color for a button in vb.net

I have placed a background image on my windows application form and when tab stops to a particular button it's color is changed and looks awkward...Can anyone tell me that how can I set some customized color for tabstop or set its value to null????
I've tried the answer from BalaR i.e. button.ShowFocusCues = falase in load event of the form but it says that it can't be used like this and it is protected
try ShowFocusCues to false
button.ShowFocusCues = false;
to hide focus rectangle.
I didn't notice it was a protected member. You have two options
use reflection to set the protected member (not recommended)
create a derived class and set the protected member as you'd like. (the right way)
class MyButton : Button
{
protected override bool ShowFocusCues
{
get { return false; }
}
}
You can also set TabStop to false.
button.TabStop = false;
if you don't want the button to obtain focus during tab cycle.

ToolStripButton = "Pressed"

I got a toolstripbutton, and when I click it, I want to make it stay "pressed" or "selected". Like a switch. And when I click another, make the pressed one "unpressed" again. Any ideas?
I think you want to use the CheckOnClick property. Set it to true, and the button should behave as you describe. In order to get (or set) the current state, use the Checked property.
Here is a full working sample:
public partial class Form1 : Form
{
private readonly IEnumerable<ToolStripButton> mutuallyExclusiveButtons;
public Form1()
{
InitializeComponent();
mutuallyExclusiveButtons = new[] { firstButton, secondButton };
}
private void ToolStripButton_Click(object sender, EventArgs e)
{
ToolStripButton button = sender as ToolStripButton;
if (button != null && button.Checked &&
mutuallyExclusiveButtons.Contains(button))
{
foreach (ToolStripButton item in mutuallyExclusiveButtons)
{
if (item != button) item.Checked = !button.Checked;
}
}
}
}
firstButton and secondButton are ToolStripButtons, both have CheckOnClick set to true, and their Clicked events hooked up to ToolStripButton_Click. This works also if there are more than two buttons in the group of buttons in which only one should be checked, just add any needed additional buttons to the mutuallyExclusiveButtons sequence.
As ChrisF said, what you are looking for is the "Checked" property. (The "CheckOnClick" property is actually not what you want, since you want a sort of mutually exclusive toggle between two ToolStripButtons.)
What you will need is to put code (into the click event of each button) that will set the Checked property of that button to True and the Checked property of the other button to False.
Actually, you can use CheckOnClick and then add code only to set the other button to False.
(Hmmm... I wonder when the Checked becomes set to True; can you capture the MouseUp etc. event of BOTH buttons into one handler, and uncheck BOTH buttons, and then CheckOnClick will check the appropriate one later? Just some geek stuff to complicate things unnecessarily in the name of simplifying things)
Maintain a flag as to what the status of a button is (pressed or normal). For each button press, call a method that refreshes the toolbar buttons to the correct state (either stay pressed or go back to normal).

How to retrieve correspoding form element from dojo event object?

If there is a html form with a button, with normal html, we would be able to retrieve form element from the onclick event object as follows.
ev.target.form
As Dojo contains a its normalize event object, how can we retrieve event generated form element when a button is clicked ? (I require this as my dom tree contains duplications of same form element)
Thank you,
nimp
dojo.connect(dojo.byId("formsContainner"), "click", function(evt){
dojo.stopEvent(evt); // assuming you don't want to actually go to a new page
var n = evt.target;
while(n.tagName != "form"){
if(n.tagName == "body") break;
n = n.parentNode;
}
if(n.tagName == "form"){
myFormMethod(n);
return;
}
console.error('no form for button - clicked on something else')
});

Eclipse RCP: Is it possible to shift the fields up without redrawing?

In my editor, I have a composite containing a label control right at the top which flashes informative message in red colour whenever the user enters erroneous inputs in any of the below lying fields. The text keeps changing dynamically depending on user's input. I am able to achieve the effect of displaying red coloured text on erroneous inputs and displaying nothing in the label for correct inputs.
But, I want that when there is no error to display in the label composite, the rest of the below fields shift up in display. And when there is error to display, the error should appear in it's place(at the top of all other fields) pushing the other fields down.
Is there a way to achieve this effect without redrawing all the controls again?
Yes, call layout (true) on the parent.
For example I have a view that has a search bar at the top who's visibility can be toggled. I have a method to create the search composite and one to remove it:
private void createNameSearchBar () {
mySearchControl = new CardSearchControl (myViewComposite, SWT.NONE);
mySearchControl.setSearchListener (this);
}
private void disposeNameSearchBar () {
mySearchControl.dispose ();
mySearchControl = null;
}
private CardSearchControl mySearchControl = null;
private Composite myViewComposite;
private boolean mySearchBarState;
To hide or show the search bar control I call this method (myViewComposite is the top level control that owns the search bar and all the other contorls):
public void setSearchBarState (boolean show) {
mySearchBarState = show;
if (myViewComposite == null || myViewComposite.isDisposed ())
return; // no work to do
if (mySearchBarState && mySearchControl == null) {
createNameSearchBar ();
mySearchControl.moveAbove (null);
myViewComposite.layout (true);
} else if (!mySearchBarState && mySearchControl != null) {
disposeNameSearchBar ();
myViewComposite.layout (true);
}
}