Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ public BaseInsertView(String page, InsertBean bean, AnnouncementForm form, URLHe

if (reshow)
{
currentRendererType = EnumUtils.getEnum(WikiRendererType.class, form.get("rendererType"), DEFAULT_MESSAGE_RENDERER_TYPE);
currentRendererType = EnumUtils.getEnum(WikiRendererType.class, form.getAsString("rendererType"), DEFAULT_MESSAGE_RENDERER_TYPE);

AnnouncementModel ann = form.getBean();
assignedTo = ann.getAssignedTo();
Expand All @@ -1084,31 +1084,31 @@ else if (null == latestPost)
cal.add(Calendar.MONTH, 1);

String expires = DateUtil.formatDate(c, cal.getTime());
form.set("expires", expires);
form.setValueToBind("expires", expires);
currentRendererType = DEFAULT_MESSAGE_RENDERER_TYPE;
assignedTo = settings.getDefaultAssignedTo();
}
else
{
// Response... set values to match most recent properties on this thread
assert null == form.get("title");
assert null == form.get("expires");
assert null == form.getAsString("title");
assert null == form.getAsString("expires");

form.set("title", latestPost.getTitle());
form.set("status", "Active"); // By default, every new response resets status to active, #35047
form.setValueToBind("title", latestPost.getTitle());
form.setValueToBind("status", "Active"); // By default, every new response resets status to active, #35047
form.setTypedValue("expires", DateUtil.formatDate(c, latestPost.getExpires()));

assignedTo = latestPost.getAssignedTo();
currentRendererType = WikiRendererType.valueOf(latestPost.getRendererType());
}

bean.assignedToSelect = getAssignedToSelect(c, assignedTo, "assignedTo", getViewContext().getUser());
bean.statusSelect = getStatusSelect(form.get("status"));
bean.statusSelect = getStatusSelect(form.getAsString("status"));
bean.renderAsSelect = getRenderAsSelect(currentRendererType);

bean.settings = settings;
User u = form.getUser() == null ? getViewContext().getUser() : form.getUser();
bean.memberList = getMemberList(u, c, latestPost, reshow ? form.get("memberList") : null);
bean.memberList = getMemberList(u, c, latestPost, reshow ? form.getAsString("memberList") : null);
bean.form = form;
bean.cancelURL = cancelURL;

Expand Down Expand Up @@ -1642,7 +1642,7 @@ public AnnouncementForm()
// XXX: change return value to typed GuidString
public String getParentId()
{
return _stringValues.get("parentid");
return getAsString("parentid");
}

AnnouncementModel selectAnnouncement()
Expand Down Expand Up @@ -1671,7 +1671,7 @@ public void validate(Errors errors)
// Validate "expires" conversion from String to Date
try
{
String expires = StringUtils.trimToNull(get("expires"));
String expires = StringUtils.trimToNull(getAsString("expires"));
if (null != expires)
DateUtil.parseDateTime(expires);
}
Expand Down Expand Up @@ -2270,7 +2270,7 @@ public ThreadView(Container c, ActionURL url, AnnouncementModel ann, Permissions
public ThreadView(AnnouncementForm form, Container c, ActionURL url, Permissions perm, boolean print)
{
this();
AnnouncementModel ann = findThread(c, form.get("rowId"), form.get("entityId"));
AnnouncementModel ann = findThread(c, form.getAsString("rowId"), form.getAsString("entityId"));
init(c, ann, url, perm, false, print);
}

Expand Down Expand Up @@ -2514,7 +2514,7 @@ public class UpdateBean
private UpdateBean(AnnouncementForm form, AnnouncementModel ann)
{
Container c = form.getContainer();
String reshowMemberList = form.get("memberList");
String reshowMemberList = form.getAsString("memberList");

annModel = ann;
settings = getSettings(c);
Expand Down
8 changes: 4 additions & 4 deletions announcements/src/org/labkey/announcements/insert.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
%><tr><td colspan="3"><span class="labkey-message">Note: This <%=h(settings.getConversationName().toLowerCase())%> will not be posted immediately; it will appear after the content has been reviewed.</span><br><br></td></tr><%
}
%>
<tr><td class='labkey-form-label'>Title * <%= helpPopup("Title", "This field is required.") %></td><td colspan="2"><labkey:input type='text' size='60' maxLength="255" id="title" name='title' value='<%=form.get("title")%>' onChange="LABKEY.setDirty(true);" /></td></tr>
<tr><td class='labkey-form-label'>Title * <%= helpPopup("Title", "This field is required.") %></td><td colspan="2"><labkey:input type='text' size='60' maxLength="255" id="title" name='title' value='<%=form.getAsString("title")%>' onChange="LABKEY.setDirty(true);" /></td></tr>
<%
if (settings.hasStatus())
{
Expand Down Expand Up @@ -101,7 +101,7 @@
}
if (settings.hasExpires())
{
%><tr><td class='labkey-form-label'>Expires</td><td><labkey:input type='text' size='23' name='expires' value='<%=form.get("expires")%>' onChange="LABKEY.setDirty(true);" /></td><td><i>By default the Expires field is set to one month from today. <br>Expired messages are not deleted, they are just no longer shown on the Portal page.</i></td></tr><%
%><tr><td class='labkey-form-label'>Expires</td><td><labkey:input type='text' size='23' name='expires' value='<%=form.getAsString("expires")%>' onChange="LABKEY.setDirty(true);" /></td><td><i>By default the Expires field is set to one month from today. <br>Expired messages are not deleted, they are just no longer shown on the Portal page.</i></td></tr><%
}
%>

Expand All @@ -119,7 +119,7 @@
<div class="tab-content" id="messageTabsContent">
<div class="tab-pane active" id="source" role="tabpanel" aria-labelledby="source-tab">
<% addHandler("body", "change", "LABKEY.setDirty(true);"); %>
<textarea cols='120' rows='15' id="body" name='body' style="width: 100%;"><%=h(form.get("body"))%></textarea>
<textarea cols='120' rows='15' id="body" name='body' style="width: 100%;"><%=h(form.getAsString("body"))%></textarea>
</div>
<div class="tab-pane message-preview form-control" id="preview" role="tabpanel" aria-labelledby="preview-tab">
</div>
Expand Down Expand Up @@ -165,7 +165,7 @@ else
%><%= generateBackButton("Cancel") %><%
}
%>
<labkey:input type="hidden" name="discussionSrcIdentifier" value='<%=form.get("discussionSrcIdentifier")%>'/>
<labkey:input type="hidden" name="discussionSrcIdentifier" value='<%=form.getAsString("discussionSrcIdentifier")%>'/>
</labkey:form>
<p/>
<%
Expand Down
8 changes: 4 additions & 4 deletions announcements/src/org/labkey/announcements/respond.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ if (!mr.isApproved(c, user, false /* Not a new thread */))

if (settings.isTitleEditable())
{
%><tr><td class="labkey-form-label">Title * <%=helpPopup("Title", "This field is required.") %></td><td colspan="2"><labkey:input type="text" size="60" maxLength="255" name="title" value='<%=form.get("title")%>' onChange="LABKEY.setDirty(true);"/></td></tr><%
%><tr><td class="labkey-form-label">Title * <%=helpPopup("Title", "This field is required.") %></td><td colspan="2"><labkey:input type="text" size="60" maxLength="255" name="title" value='<%=form.getAsString("title")%>' onChange="LABKEY.setDirty(true);"/></td></tr><%
}
else
{
%><tr><td colspan="2"><labkey:input type="hidden" name="title" value='<%=form.get("title")%>'/></td></tr><%
%><tr><td colspan="2"><labkey:input type="hidden" name="title" value='<%=form.getAsString("title")%>'/></td></tr><%
}

if (settings.hasStatus())
Expand Down Expand Up @@ -111,7 +111,7 @@ if (settings.hasMemberList())

if (settings.hasExpires())
{
%><tr><td class="labkey-form-label">Expires</td><td><labkey:input type="text" size="23" name="expires" value='<%=form.get("expires")%>' onChange="LABKEY.setDirty(true);"/></td><td><i>Expired messages are not deleted, they are just no longer shown on the Portal page.</i></td></tr><%
%><tr><td class="labkey-form-label">Expires</td><td><labkey:input type="text" size="23" name="expires" value='<%=form.getAsString("expires")%>' onChange="LABKEY.setDirty(true);"/></td><td><i>Expired messages are not deleted, they are just no longer shown on the Portal page.</i></td></tr><%
}

%>
Expand All @@ -129,7 +129,7 @@ if (settings.hasExpires())
<div class="tab-content" id="messageTabsContent">
<div class="tab-pane active" id="source" role="tabpanel" aria-labelledby="source-tab">
<% addHandler("body", "change", "LABKEY.setDirty(true);"); %>
<textarea cols='120' rows='15' id="body" name='body' style="width: 100%;"><%=h(form.get("body"))%></textarea>
<textarea cols='120' rows='15' id="body" name='body' style="width: 100%;"><%=h(form.getAsString("body"))%></textarea>
</div>
<div class="tab-pane message-preview form-control" id="preview" role="tabpanel" aria-labelledby="preview-tab">
</div>
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/action/BaseViewAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ private boolean hasStringValue(String propertyName)
}
if (o instanceof String s)
{
return null != StringUtils.trimToNull(s);
return !StringUtils.isBlank(s);
}
if (o instanceof String[] strings)
{
for (String s : strings)
{
if (null != StringUtils.trimToNull(s))
if (!StringUtils.isBlank(s))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ public void renderInputHtml(RenderContext ctx, HtmlWriter out, Object value)
protected Object getInputValue(RenderContext ctx)
{
TableViewForm viewForm = ctx.getForm();
return viewForm.getStrings().get(_inputName);
return viewForm.getValuesToBind().get(_inputName);
}
}

Expand Down
84 changes: 76 additions & 8 deletions api/src/org/labkey/api/data/BeanViewForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.labkey.api.action.HasBindParameters;

import java.util.HashMap;
import java.util.Map;


public class BeanViewForm<K> extends TableViewForm implements DynaBean
public class BeanViewForm<K> extends TableViewForm implements DynaBean, HasBindParameters
{
private final StringBeanDynaClass _dynaClass;
private final Class<K> _wrappedClass;

protected BeanViewForm(Class<K> clss)
Expand All @@ -39,9 +42,10 @@ public BeanViewForm(Class<K> clss, TableInfo tinfo)
}


public BeanViewForm(Class<K> clss, TableInfo tinfo, Map<String, Class> extraProps)
public BeanViewForm(Class<K> clss, TableInfo tinfo, Map<String, Class<?>> extraProps)
{
super(StringBeanDynaClass.createDynaClass(clss, extraProps), tinfo);
super(tinfo);
_dynaClass = StringBeanDynaClass.createDynaClass(clss, extraProps);
_wrappedClass = clss;
}

Expand All @@ -60,7 +64,7 @@ public K getBean()
else
bean = (K) BeanUtils.cloneBean(_oldValues);

factory.fromMap(bean, getStrings());
factory.fromMap(bean, getValuesToBind());
return bean;
}
catch (ReflectiveOperationException x)
Expand All @@ -71,7 +75,7 @@ public K getBean()
else
{
ObjectFactory<K> factory = ObjectFactory.Registry.getFactory(_wrappedClass);
return factory.fromMap(getStrings());
return factory.fromMap(getValuesToBind());
}
}

Expand All @@ -83,19 +87,19 @@ public void setBean(K bean)
}

@Override
public Map<String, String> getStrings()
public Map<String, Object> getValuesToBind()
{
//If we don't have strings and do have typed values then
//make the strings match the typed values
Map<String, String> strings = super.getStrings();
Map<String, Object> strings = super.getValuesToBind();
if (null == strings || strings.isEmpty() && (null != _values && !_values.isEmpty()))
{
strings = new HashMap<>();
for (Map.Entry<String, Object> entry : _values.entrySet())
{
strings.put(entry.getKey(), ConvertUtils.convert(entry.getValue()));
}
_stringValues = strings;
setValuesToBind(strings);
}

return strings;
Expand All @@ -118,4 +122,68 @@ else if (o instanceof Map)
throw new IllegalArgumentException("Type of old values is incompatible with wrapped class");
}
}

@Override
protected Class<?> getTruePropType(String propName)
{
var ret = _dynaClass.getTruePropType(propName);
if (null == ret)
ret = super.getTruePropType(propName);
return ret;
}

// DynaBean
@Override
public DynaClass getDynaClass()
{
return _dynaClass;
}

@Override
public Object get(String name)
{
return super.getValueToBind(name);
}

@Override
public void set(String name, Object value)
{
super.setValueToBind(name,value);
}

@Override
public boolean contains(String arg0, String arg1)
{
throw new UnsupportedOperationException("No mapped properties in a table");
}

@Override
public Object get(String arg0, String arg1)
{
throw new UnsupportedOperationException("No mapped properties in a table");
}

@Override
public Object get(String arg0, int arg1)
{
throw new UnsupportedOperationException("No indexed properties in a table");
}

@Override
public void remove(String arg0, String arg1)
{
throw new UnsupportedOperationException("No indexed properties in a table");
}

@Override
public void set(String arg0, String arg1, Object arg2)
{
throw new UnsupportedOperationException("No mapped properties in a table");
}

@Override
public void set(String arg0, int arg1, Object arg2)
{
throw new UnsupportedOperationException("No indexed properties in a table");
}
}
15 changes: 10 additions & 5 deletions api/src/org/labkey/api/data/ColumnRenderPropertiesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -785,24 +785,29 @@ public final Class<?> getJavaClass()

@Override
public Class<?> getJavaClass(boolean isNullable)
{
return defaultJavaClass(this, isNullable);
}

public static Class<?> defaultJavaClass(ColumnRenderProperties col, boolean isNullable)
{
Class<?> ret;
boolean isNumeric;
PropertyType pt = getPropertyType();
PropertyType pt = col.getPropertyType();
if (pt != null)
{
ret = pt.getJavaType();
isNumeric = pt.getJdbcType().isNumeric();
}
else
{
ret = getJdbcType().getJavaClass(isNullable);
isNumeric = getJdbcType().isNumeric();
JdbcType jdbcType = col.getJdbcType();
ret = jdbcType.getJavaClass(isNullable);
isNumeric = jdbcType.isNumeric();
}

if (isNumeric)
{
Unit unit = getDisplayUnit();
Unit unit = col.getDisplayUnit();
if (null != unit)
return unit.getQuantityClass();
}
Expand Down
Loading